/*菜单组件
  Create At 2017-12-16
*/
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    selectIndex:{
      type: Number,
      value:1
    }
  },
  attached:function(){
    var data = this.data;
    
    var selectIndex = data.selectIndex;
    var menuList = data.menuList;

    for (var menuIndex = 0; menuIndex < menuList.length; menuIndex++){
      
      if (menuList[menuIndex].index==selectIndex){
        menuList[menuIndex].imageUrl = menuList[menuIndex].tiggerImageUrl;
        menuList[menuIndex].textColor = menuList[menuIndex].tiggerColor;
        break;
      }

    }

    this.setData({
      "menuList":menuList
    });
  },
  /**
   * 组件的初始数据
   */
  data: {
    menuList:[{
      index:1,
      text:"按揭推介",
      textColor:"gray",
      tiggerColor:"#ed2c33",
      imageUrl: app.maImgburl.webUrl+ "/menu-home.png",
      tiggerImageUrl: app.maImgburl.webUrl +"/menu-home-check.png",
      link:"/pages/Home/Home"
    },
    {
      index:2,
      text:"每月供款",
      textColor: "gray",
      tiggerColor: "#ed2c33",      
      imageUrl: app.maImgburl.webUrl +"/menu-time.png",
      tiggerImageUrl: app.maImgburl.webUrl +"/menu-time-check.png",
      link: "/pages/MonthlyPay/MonthlyPay"
    },
    {
      index: 3,
      text:"置業預算",
      textColor: "gray",
      tiggerColor: "#ed2c33",      
      imageUrl: app.maImgburl.webUrl +"/menu-record.png",
      tiggerImageUrl: app.maImgburl.webUrl +"/menu-record-check.png",
      link: "/pages/Purchasing/Purchasing"
    },
    {
      index:4,
      text:"稅務費用",
      textColor: "gray",
      tiggerColor: "#ed2c33",     
      imageUrl: app.maImgburl.webUrl +"/menu-list.png",
      tiggerImageUrl: app.maImgburl.webUrl +"/menu-list-check.png",
      link:"/pages/Tax/Tax"
    },
    {
      index:5,
      text:"樓按百科",
      textColor: "gray",
      tiggerColor: "#ed2c33",      
      imageUrl: app.maImgburl.webUrl +"/menu-file.png",
      tiggerImageUrl: app.maImgburl.webUrl +"/menu-file-check.png",
      link:"/pages/Encyclopedia/Encyclopedia"
    }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    setMenu:function(menuIndex){
      
    },

    navPage: function (event) {
      var pageUrl = event.currentTarget.dataset.url;
      var PageLength=getCurrentPages().length;
      
      if(PageLength<5){
        wx.redirectTo({
          url: pageUrl
        });
      }
      else{
        wx.reLaunch({
          url: pageUrl
        })
      }
    }

  }
});



